/**
 * Created by jiaaobo on 16/11/29.
 */

import Banner from "../../../common/component/Banner";
import Util from "util";
import API  from "api";

export default{
    name : "exchange-main",
  data(){
    return{
      disabled : true,
      couponCode : ''
    }

  },
  methods : {
    onInputCode : function(e){
      if(this.couponCode){
        this.disabled = false;
      }
      else{
        this.disabled = true;
      }
    },

    onExchange : function(e){

      let params  = {
        userId : 1
      }

      //规则兑换
      if(!Util.Validate.isChinese(this.couponCode)){
        params.couponCode = this.couponCode;
        params.type = "code";
      }
      else{
        params.keyword = this.couponCode;
        params.type = "keyword";
      }

      API.biz.exchangeVoucher(params,{hasLoading : true})
        .then((res)=>{
            Util.UI.toast("兑换成功!");
            this.couponCode = "";
            window.getRouter().go(-1);
        })
    }
  },
  computed : {

  },
  components:{
  }
}
